<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>双列管审批</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css"/>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css"/>
    <link href="/static/css/default.css" rel="stylesheet" type="text/css"/>
    <style>
        .discell {
            text-align: right;
            width: 180px;
        }

        .input {
            width: 150px;
        }
    </style>
</head>
<body>
<div class="mini-fit">
    <div style="height:100%;width: 100%;overflow-x: auto;overflow-y: auto;">
        <form id="form1" method="post" style="margin-left: 40px;">
            <input name="mid" id="mid" class="mini-hidden" style="width: 100%" readonly/>
            <input name="pid" id="priNum" class="mini-hidden" style="width: 100%" readonly/>
            <br>
            <table style="height: 100%;width: 100%;">
                <tr>
                    <td class="discell">申请司法所:</td>
                    <td class="input" colspan="2">
                        <input property="editor" class="mini-textbox" id="shenqingname" name="shenqingname" readonly style="width: 300px"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell">申请时间:</td>
                    <td class="input" colspan="2">
                        <input property="editor" class="mini-textbox" id="shenDate" name="shenDate" style="width: 300px" readonly/>
                    </td>
                </tr>
                <tr>
                    <td class="discell">申请原因:</td>
                    <td class="input" colspan="2" >
                        <input name="shenReason" id="shenReason" class="mini-textarea" style="width: 300px;height: 50px"  readonly/>
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold" class="discell">租房合同:</td>
                    <td style="font-size: 10px;">
                        <input type="button" value="下载文件" onclick="onFileUpload('zf')">
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold" class="discell">工作合同:</td>
                    <td style="font-size: 10px;">
                        <input type="button" value="下载文件" onclick="onFileUpload('gz')">
                    </td>
                </tr>
                <tr>
                    <td class="discell">审批状态:</td>
                    <td class="input" colspan="2">
                        <input name="shenStatef" id="shenStatef" class="mini-radiobuttonlist"
                               data="[{ id: 1, name: '接收' },{ id: 3, name: '不接收' }]"
                               textField="name" valueField="id" value="1" required="true"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>审批原因:</td>
                    <td class="input" colspan="2">
                        <input class="mini-textarea" id="reason" name="reason" emptyText = "审批原因" required="true"
                               style="width: 300px"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>审批人:</td>
                    <td class="input" colspan="2">
                        <input property="editor" class="mini-textbox" id="approvalName" name="approvalName" style="width: 300px" required="true"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell">审批人手机号码:</td>
                    <td class="input" colspan="2">
                        <input property="editor" class="mini-textbox" id="approvalPhone" value="${phone!''}" onvaluechanged="checkPhone(2)" name="approvalPhone" style="width: 300px"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell">审批人固话:</td>
                    <td class="input" colspan="2">
                        <input property="editor" class="mini-textbox" id="approvalTel1" value="${telPhone!''}"onvaluechanged="checkPhone(1)" name="approvalTel1" style="width: 300px"/>
                    </td>
                </tr>
                <tr>
                    <td class="input" colspan="2">
                        <input  class="mini-hidden" id="approvalTel"  name="approvalTel" />
                    </td>
                </tr>
            </table>
        </form>
        <div style="padding:2px;margin: 0 auto;text-align: center">
            <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData()">确定</a>
            <a class="mini-button" iconCls="fa-save" plain="true" onclick="onCancel()">取消</a>
        </div>
    </div>
</div>
<script type="text/javascript">

    mini.parse();
    var form = new mini.Form("form1");
    var mid = mini.get("mid");
    var priNum = mini.get("priNum");
    var shenDate = mini.get("shenDate");
    var shenReason = mini.get("shenReason");
    var shenqingname = mini.get("shenqingname");
    var shenStatef = mini.get("shenStatef");
    var reason = mini.get("reason");
    var approvalName = mini.get("approvalName");
    var approvalTel1 = mini.get("approvalTel1");
    var approvalPhone = mini.get("approvalPhone");

    // 保存数据
    function saveData() {
        form.validate();
        if (form.isValid() == false) {
            return;
        }
        var phone = approvalPhone.getValue();
        var tel = approvalTel1.getValue();
        var newPhone = checkTelAndPhone(tel,phone);
        var flag = newPhone['flag'];
        var kflag = newPhone['kflag'];
        if ('-1' === kflag) {
            mini.alert("请至少输入一个联系方式");
            return;
        }
        if (flag) {
        } else {
            mini.alert("手机号码或固话有误，请重填");
            return;
        }
        mini.get("approvalTel").setValue(newPhone['newTelAndPhone']);
        var data = form.getData();
        var json = mini.encode(data);
        // 审批时增加二次弹框
        mini.confirm("确定要进行审批?","确定?",function(action){
            if (action == "ok"){
                $.ajax({
                    url : "/azbj/azbjgl/slg/jzdapprove/save",
                    data : {data: json},
                    type : "post",
                    success: function (success){
                        if(success.code == 1){
                            mini.alert("审核成功","信息提示",function () {
                                onCancel();
                            });
                        } else if(success.code == 2){
                            mini.alert(success.data);
                        } else if (success.code == 5599) {
                            mini.alert(success.message);
                        } else{
                            mini.alert("审核失败");
                        }
                    }
                });
            }else{
                return;
            }
        })
    }

    function setData() {
        $.ajax({
            url: "/azbjgl/slgapproval/getinfo?priNum=" + priNum.getValue(),
            type: "post",
            dataType: "json",
            success: function (jzdata) {
                shenDate.setValue(jzdata.shenDate);
                shenReason.setValue(jzdata.shenReason);
                shenqingname.setValue(jzdata.shenqingname);
                if(jzdata.shenStatef == "2" || jzdata.shenStatef == "4"){
                    shenStatef.setValue(1);
                }else{
                    shenStatef.setValue(jzdata.shenStatef);
                }
                approvalName.setValue(jzdata.approvalName);
                var username = "${username!''}";
                approvalName.setValue(username);
                reason.setValue(jzdata.reason);
            }
        });
    }

    function onFileUpload(e) {

        // 业务标识(2头像 3指纹 4改造表现 5心里健康 6购房合同 7租房合同 8工作合同 9其他证明材料)
        var midval = mid.getValue();
        var prival = priNum.getValue();
        var taskid = "";
        if(e == "gf"){
            taskid = "6";
        }else if(e == "zf"){
            taskid = "7";
        }else if(e == "gz"){
            taskid = "8";
        }else if(e == "qt"){
            taskid = "9";
        }
        var nouploadflag = "5000";
        var url = "/upload/user/uploadAppendixfile/noupload/view?1=1&id="+midval+"&priNum="+prival+"&taskId=" + taskid +"&nouploadflag="+nouploadflag;

        commonEdit(url, null, null,600, 400, true,true,true);
    }

    window.onload = function () {
        mini.get("shenqingname").setEnabled(false);
        mini.get("shenDate").setEnabled(false);
        mini.get("shenReason").setEnabled(false);
        mid.setValue(${id!''});
        priNum.setValue(${priNum!''});
        setData();
    }

    function checkPhone(e) {
        var phone = approvalPhone.getValue();
        var telPhone = approvalTel1.getValue();
        if (e == '1') {
            if(!validateTel(telPhone)) {
                mini.alert("固定电话有误，请重填");
            }
        }
        if (e == '2') {
            if(!validatePhone1(phone)) {
                mini.alert("手机号码有误，请重填");
            }
        }
    }

</script>
</body>
</html>